Thanks
declaratively
ItemStyle-Width="150px"
would work as well as if you specify it via code (via DataGrid's Columns
collection) but then something like:
DataGrid1.Columns(0).ItemStyle.Width=Unit.Pixel(150)
That's all I can really say without knowing more about your scenario. If
this doesn't help, please provide bit more details.
--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
"Nedu N" <ned...@hotmail.com> wrote in message
news:OcDf9sr3...@tk2msftngp13.phx.gbl...
Thank you for using MSDN Newsgroup! My name is Jeffrey, and I will be
assisting you on this issue.
Based on my understanding, you want to get the fully control of the column
width of the web form datagrid control.
==================================================
1). If your column is customized column, you can control it through
ItemStyle in the Html designer:
<asp:TemplateColumn>
<ItemTemplate>
..............
</ItemTemplate>
<ItemStyle Width=50px></ItemStyle>
</asp:TemplateColumn>
2). For auto generated column, you can control it before render(At
runtime), like this:
private void Page_Load(object sender, System.EventArgs e)
{
sqlDataAdapter1.Fill(dataSet11);
DataGrid1.DataBind();
DataGrid1.Columns[0].ItemStyle.Width=Unit.Pixel(100);
}
Actually, the datagrid control will render as <table> html tag.After
setting its column width, .Net will add "width" attribute to all the <td>
in that column.(You can determine this through view html source in page)
Note: If your column's width is very small, IE will wrap the text in all
the cells(<td> tags) in that column, so the whole datagrid height
increased. But IE will not wrap a single word, so there are a minimal size
for the width to take effect.(The minimal size is the longest word in that
column)
For example, if I set a column width to 5px, which is smaller than most of
the words, then the text in <td> will like this:
//First <td>
Public
Relations
Manager
//Second <td>
Sales
Representative
//Third <td>
Operations
Manager
So this column's width will be the width of word "Representative".(Because
it is the longest word in that column). If you view the source, you will
see that all the <td> still have width attribute with value 10px. So this
is the default behavior of IE browser not Asp.net.
Hope this make sense to you.
=================================================================
Please apply my suggestion above and let me know if it helps resolve your
problem.
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Hope you have a nice experience in Microsoft Newsgroup!
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.